$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});

$("#createDate").datetimepicker({
	format: "yyyy-mm-dd",
    autoclose: true,
    //forceParse: true,
    clearBtn: true,
    todayBtn: true,
    todayHighlight: true,
    showMeridian: true,
    pickerPosition: "bottom-left",
    language: 'zh-CN',//中文，需要引用zh-CN.js包
    startView: 2,//月视图
    minView: 2//日期时间选择器所能够提供的最精确的时间选择视图
});

function save() {
	/*if(userNum()<3){
		alert("请至少邀请2个队员");
		return;
	}*/
	$.ajax({
		cache : true,
		type : "POST",
		url : "/act/actTeam/save",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name : {
				required : true
			}
		},
		messages : {
			name : {
				required : icon + "请输入姓名"
			}
		}
	})
}

var openUser = function(){
	layer.open({
		type:2,
		title:"选择人员",
		area : [ '300px', '450px' ],
		content:"/sys/user/treeView"
	})
}

function loadUser(userIds,userNames){
	$("#userIds").val(userIds);
	console.log($("#userIds").val());
	$("#userNames").val(userNames);
	/*if(userNum()<3){
		alert("请至少选择2个");
	}else if(userNum()>3){
		$("#duo").attr("checked",'true');
	}else{
		$("#shuang").attr("checked",'true');
	}*/
}

function userNum(){
	var arr = $("#userNames").val();
	var ss = arr.split(",");
	return ss.length;
}
